package com.neutech.controller;

import com.neutech.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
public class ScheduleController {
    @Autowired
    private ScheduleService scheduleService;

    @RequestMapping("/querydoctor")
    @ResponseBody
    public List<Map<String ,Object>> queryDoctorByRoom(@RequestParam Map map)
    {
        List<Map<String,Object>> list = scheduleService.queryDoctorByRoom(map.get("room").toString());
        System.out.println(list);
        return scheduleService.queryDoctorByRoom(map.get("room").toString());
    }

    @RequestMapping("/queryschedule")
    @ResponseBody
    public List<Map<String,Object>> queryScheduleById(@RequestParam Map map){
        List<Map<String,Object>> list = scheduleService.queryScheduleById(Integer.parseInt(map.get("id").toString()));
        System.out.println(list);
        return scheduleService.queryScheduleById(Integer.parseInt(map.get("id").toString()));
    }

    @RequestMapping("/addschedule")
    @ResponseBody
    public void updateSchedule(@RequestParam Map map){
        for(Object key:map.keySet()){
            String value = (String) map.get(key);
            System.out.println(key + ":" + value);
        }
        scheduleService.addSchedule(map);
    }

    @RequestMapping("/deleteschedule")
    @ResponseBody
    public void deleteScheduleById(@RequestParam Map map){
        System.out.println(map.get("id"));
        scheduleService.deleteScheduleById(Integer.parseInt(map.get("id").toString()));

    }
}
